<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * The path to the "home" route for your application.
     *
     * @var string
     */
    public const HOME = '/home';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        //
        Route::pattern('id', '[0-9]+');
        Route::pattern('is', '(0|1)');
        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $clientAppType = defined('CLIENT_APP_TYPE') ? CLIENT_APP_TYPE : 'web';
        if($clientAppType == 'admin'){
            $this->mapAdminRoutes();
        }else{
            $this->mapWapRoutes();
        }
    }

    /**
     * Define the "api" routes for the application.
     * These routes are typically stateless.
     * @return void
     */
    protected function mapWapRoutes()
    {
        Route::middleware('wap')
            ->prefix('wap')
            ->namespace('App\Http\Controllers\Wap')
            ->group(base_path('routes/wap.php'));
    }

    /**
     * Define the "api" routes for the application.
     * These routes are typically stateless.
     * @return void
     */
    protected function mapAdminRoutes()
    {
        Route::middleware('admin')
            ->prefix('backstage')
            ->namespace('App\Http\Controllers\Admin')
            ->group(base_path('routes/admin.php'));
    }
}
